import json
import random
import time
import requests
from DataTest.JsonData.read_json import load_json
from DataTest.ANR.path import *

mood = {'1': '心动', '2': '开心', '3': '伤心', '4': '平静', '5': '烦躁', '6': '心累', '7': '生气', '8': '兴奋'}


def new_daily():

    self_token_list, match_token_list = load_json(json_data_path)

    url = 'http://124.220.33.63:8700/diary'

    with open(json_data_path, 'r', encoding='utf-8') as file:

        data = json.load(file)
        self_id_list = [item.get('self_data').get('id') for item in data.get('data')]

    user_data = dict(zip(self_id_list, self_token_list))

    # match_id_list = [item.get('match_data').get('id') for item in data.get('data')]
    for self_id, token in user_data.items():

        header = {
            'Authorization': f'Bearer {token}',
            'Content-Type': 'application/json',
        }

        key = random.choice(list(mood))
        value = mood[key]

        timer = str(int(time.time() * 1000))

        data = {
            "MoodID": key,
            "Resources": [{
                "Type": "image",
                "Url": f"https://cdn.codeffect.top/test/suki/user/image/diary0/{self_id}/{timer}"
            }],
            "Text": f"用户{token}写的日记，心情是{value}",
            "Date": "20241020",
            "Label": "约会日常",
            "Voice": None
        }

        res = requests.post(url=url, headers=header, json=data)

        if res.status_code == 200:
            print(f'用户{token}写的日记，心情是{value}')

        else:
            print(f'用户{token}写日记失败')


if __name__ == '__main__':
    new_daily()
